//
//  MainViewController.swift
//  01sinablog
//
//  Created by ZhangZiang on 15/12/12.
//  Copyright © 2015年 ZhangZiang. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    @objc private func composeBtnClicked() {
        
        let vc = ComposeViewController()
        
        let nav = UINavigationController(rootViewController: vc)
        
        //modal界面
        presentViewController(nav, animated: true, completion: nil)
    }
    
    let mainTabBar = MainTabBar()
    
    override func viewDidLoad() {
        super.viewDidLoad()

//        print(self.tabBar.classForCoder)
        self.setValue(mainTabBar, forKey: "tabBar")
//        print(self.tabBar.classForCoder)
        // Do any additional setup after loading the view.
        addMyChildViews(HomeViewController(), imageStr: "tabbar_home", title: "首页")
        addMyChildViews(MessageViewController(), imageStr: "tabbar_message_center", title: "消息")
        addMyChildViews(DiscoverViewController(), imageStr: "tabbar_discover", title: "发现")
        addMyChildViews(ProfileViewController(), imageStr: "tabbar_profile", title: "我")
    
         //给compose方法加事件
        mainTabBar.composeBtn.addTarget(self, action: "composeBtnClicked", forControlEvents: .TouchUpInside)
    }
    
    private func addMyChildViews (vc : UIViewController, imageStr : String, title : String) -> Void
    {
        //把tabBar设置为橘色
//        UITabBar.appearance().tintColor = UIColor.orangeColor()
        
        let nav = BaseNavigationController(rootViewController: vc)
        
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageStr)
//        vc.tabBarItem.selectedImage = UIImage(named: String(format: "%@_highlighted", imageStr))?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        addChildViewController(nav)
    }
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
